package com.rzwl.single.server.config;

import com.google.common.base.Predicates;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @author : championjing
 * @ClassName: SwaggerConfig
 * @Description:
 * @Date: 2019/12/25 0025 14:10
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${swagger.host}")
    private String swaggerHost;

    @Bean
    public Docket CreateRestApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.rzwl.single.server.ctrl"))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .paths(PathSelectors.any())
                .build().directModelSubstitute(Timestamp.class, Date.class);
        /*if (StringUtils.isNotBlank( swaggerHost )) {
            docket.host( swaggerHost );
        }*/
        return docket;
    }


    private ApiInfo apiInfo () {
        return new ApiInfoBuilder()
                .title("patent manager")
                .description("no description")
                .version("V1.0")
                .build();
    }
}
